package com.gsmmodem;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.ArrayList;




public class MsgSendClient extends Thread {
	public static ArrayList sendBuffer = new ArrayList();
	Socket s = new Socket();
	BufferedWriter out = null;

	public MsgSendClient(Socket s) {
		this.s = s;
		try {
			out = new BufferedWriter(
					new OutputStreamWriter(s.getOutputStream()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	public void run() {
		String msg ="";
		while (true) {
			if (sendBuffer != null
					&& sendBuffer.size() > 0) {
				
				synchronized (sendBuffer) {
				
					 msg = (String) sendBuffer.remove(0);
				}
				try {
					msg = msg + "\r\n" ;
					out.write(msg);
					out.flush();
					System.out.println("msg send to Msg modem:" + "\n" + msg);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			try {
				sleep(50);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
